import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:library_base/base/base_app_state_page.dart';
import 'package:library_base/constant/constant.dart';
import 'package:library_base/ext/theme_data_ext.dart';
import 'package:library_base/global/multi_language.dart';
import 'package:library_base/res/decoration.dart';
import 'package:library_base/res/dividing_line.dart';
import 'package:library_base/res/edge.dart';
import 'package:library_base/res/gaps.dart';
import 'package:library_base/res/styles.dart';
import 'package:library_base/utils/theme_util.dart';
import 'package:library_base/widget/button/gradient_button.dart';
import 'package:library_base/widget/dialog/create_delivery_note_controller.dart';
import 'package:library_base/widget/dialog/incoming_orders_filter_controller.dart';
import 'package:library_base/widget/image/local_image.dart';

class IncomingOrdersFilterDialog extends StatefulWidget {
  const IncomingOrdersFilterDialog({
    Key? key,
  }) : super(key: key);

  @override
  State<IncomingOrdersFilterDialog> createState() => _IncomingOrdersFilterDialogState();
}

class _IncomingOrdersFilterDialogState
    extends BaseState<IncomingOrdersFilterDialog, IncomingOrdersFilterController> {
  @override
  isListenLifeCycle() => false;

  @override
  void onCreate() {
    setNavigationBarVisible(false);
    setStatusBarVisible(false);
    setBackgroundColor(Colors.transparent);
  }

  @override
  Widget? getMainWidget(BuildContext context) {
    return Stack(
      children: [
        GestureDetector(onTap: () => Get.back()),
        GestureDetector(
          onTap: () {},
          child: Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              SizedBox(height: 0.3.sh),
              Row(
                children: [
                  SizedBox(width: 0.06.sw),
                  Container(
                    width: 0.88.sw,
                    decoration: rs8,
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        SizedBox(
                          height: 95.w,
                          width: double.infinity,
                          child: Stack(
                            children: [
                              Container(
                                  alignment: Alignment.center,
                                  child: Text(MultiLanguage.orderFiltering.tr,
                                      style: normalTextColor34)),
                              Positioned(
                                top: 10.w,
                                right: 0,
                                child: GestureDetector(
                                  onTap: () => Get.back(),
                                  child: Padding(
                                      padding: edgeAll24,
                                      child: LocalImage('common_close',
                                          package: Constant.packLib(), width: 26.r, height: 26.r)),
                                ),
                              )
                            ],
                          ),
                        ),
                        // gapH24,
                        line1,
                        Column(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                        gapH24,
                        buildItem(
                            onTap: baseGetxController!.chooseLoadingTime,
                            title: MultiLanguage.creationTime.tr,
                            hint: MultiLanguage.pleaseSelectCreationTime.tr,
                            content: baseGetxController!.loadingTime),
                        gapH24,
                        buildItem(
                            onTap: baseGetxController!.chooseWarehouse,
                            title: MultiLanguage.warehouse.tr,
                            hint: MultiLanguage.pleaseSelectTheWarehouse.tr,
                            content: baseGetxController!.warehouse.value != null
                                ? baseGetxController!.warehouse.value!.whName
                                : null),
                        gapH24,
                        ]),
                        line1,
                        Container(
                          padding: edgeAll24,
                          child: Row(
                            children: [
                              Expanded(
                                child: GradientButton(
                                  ThemeUtil.getTheme(),
                                  radius: const BorderRadius.only(
                                      topLeft: Radius.circular(50), bottomLeft: Radius.circular(50)),
                                  colors: ThemeUtil.getTheme().buttonLeftBgColor(),
                                  height: 80.w,
                                  text: MultiLanguage.reset.tr,
                                  onPressed: baseGetxController!.resetFilter,
                                ),
                              ),
                              Expanded(
                                child: GradientButton(
                                  ThemeUtil.getTheme(),
                                  radius: const BorderRadius.only(
                                      topRight: Radius.circular(50),
                                      bottomRight: Radius.circular(50)),
                                  height: 80.w,
                                  text: MultiLanguage.filter.tr,
                                  onPressed: baseGetxController!.loginEnabled.value
                                      ? baseGetxController!.platoon
                                      : null,
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ],
          ),
        )
      ],
    );
  }

  buildItem(
      {GestureTapCallback? onTap, required String title, required String hint, String? content}) {
    return Row(children: [
      Expanded(
          flex: 2, child: Text(title, style: TextStyles.textNormal28, textAlign: TextAlign.end)),
      Gaps.hGap24,
      Expanded(
          flex: 7,
          child: GestureDetector(
            onTap: onTap,
            child: Container(
                padding: edgeAll24,
                decoration: BoxDecoration(
                    borderRadius: const BorderRadius.all(Radius.circular(30.0)),
                    border:
                        Border.all(color: ThemeUtil.getTheme().secondaryTextColor(), width: 1.0)),
                child: Row(children: [
                  Expanded(
                      child: Text(content == null || content.isEmpty ? hint : content,
                          style: content == null || content.isEmpty
                              ? TextStyles.textSecondary28
                              : TextStyles.textNormal28)),
                  LocalImage('common_grey_rightward_arrow',
                      package: Constant.packLib(), width: 20.w, height: 20.w),
                ])),
          )),
      gapW24,
    ]);
  }

  @override
  IncomingOrdersFilterController? registerController() => Get.put(IncomingOrdersFilterController());
}
